var app = new Vue({
  el: '#app',
  data () {
    return {
      data: null,
      errMsg: ''
    }
  },
  created () {
    this.getData()
  },
  watch: {
    errMsg (val) {
      if (val) {
        setTimeout(() => {
          this.errMsg = ''
        }, 1500)
      }
    }
  },
  methods: {
    // 返回
    goback () {
      window.history.go(-1);
    },
    // 获取数据
    getData () {
      let id = getUrlParam("id")
      Axios.post('/goods/order/getOrderDetails.do', {
          ordersId: id
      }).then(res => {
        if (res.respCode === 'S') {
          let data = res.data
          if (data.deliveryTime) {
            data.deliveryTime = new Date(data.deliveryTime).Format('yy-MM-dd hh:mm')
          }
          this.data = data
        }  				
	  }).catch(err => {
          console.error(err)
      })
    },
    // 取消订单
    btnCancel () {
      Axios.post('/goods/order/updateOrderStatus.do',{
        ordersId: this.data.ordersId,
        userStatus: "CANCELED"
      }).then(res => {
        if (res.respCode === "S") {
          this.data.status = "CANCELED"
        }        
			}).catch(err => {
        console.error(err)
      })
    },
    // 确认收货
    btnOk () {
      Axios.post('/goods/order/updateOrderStatus.do',{
        ordersId: this.data.ordersId,
        userStatus: "FINISHED"
      }).then(res => {
        if (res.respCode === "S") {
          this.data.status = "FINISHED"
          window.location.href = "../order/member_order.html"
        }        
			}).catch(err => {
        console.error(err)
      })
    },
    // 再次/继续购买
    btnBuy () {
      Axios.post('/goods/order/againOrders.do',{
        ordersId: this.data.ordersId
      }).then(res => {
        if (res.respCode === 'S') {
          if (res.data === 'success') {            
            window.location.href = "../shopping/shopping.html"
          } else if (res.data === 'no_price')  {
            this.errMsg = '该商品已下架，暂无价格'
          }          
        } else {
          if (res.data === 'defeat') {
            this.errMsg = '加入购物车失败！'
          }
        }
			}).catch(err => {
        console.error(err)
      })
    },
    // 全部拒收
    btnAllRejection () {
      let id = this.data.ordersId
      window.location.href = "member_order_allRejection.html?id=" + id
    }
  }
})